

-----------------------------------------------------------------------------------------
--
-- gmain.lua
--
-----------------------------------------------------------------------------------------

	local storyboard 	= 	require( "storyboard" )
	local scene 		= 	storyboard.newScene()
	local groupMain 	= 	nil
	-- include Corona's "widget" library
	local widget 		= 	require "widget"
	
	local gamemode = "PLAY"
        -- Game sound
--        local backgroundSound = audio.loadStream( "audios/start.mp3" )
--        local bgSoundActive = true
--        audio.setVolume( 1.0 )
--        audio.setVolume( 0.75, { channel=1 } )
--
--        local gameMusicChannel;
--        local isChanelActive;
        
        local groupMain        
	
	function scene:clearAll()
		while groupMain.numChildren > 0 do
                    if groupMain[groupMain.numChildren].Timer then
                        timer.cancel(groupMain[groupMain.numChildren].Timer)
                    end
                    groupMain[groupMain.numChildren]:removeSelf()
		end
	end
	-----------------------------------------------------------------------------------------
	-- Called when the scene's view does not exist:
	-----------------------------------------------------------------------------------------
	function scene:createScene( event )
		local group = self.view
                -- init music for this level
--                gameMusicChannel = audio.play( backgroundSound, { channel=1, loops=-1, fadein=5000 }  )
		-- display a background image
		local background = display.newImageRect( "images/bg_gmain.png", _W, _H )
		background:setReferencePoint( display.TopLeftReferencePoint )
		background.x, background.y = 0, 0
		group:insert( background )
                
                groupMain = display.newGroup()
		group:insert( groupMain )
		local btnStart = widget.newButton{
			label="Bắt đầu",
			labelColor = {default={248,217,6}, over={128} },
                        fontSize = 36,
			default="images/btn_on.png",
			over="images/btn_over.png",
--			width=54, height=40,
			onRelease = function(event)
				---showMenuPopup()
--                              storyboard.gotoScene( "gmain")  
			end
		}
                btnStart.xScale, btnStart.yScale = 0.315, 0.48
		btnStart.x = _W * 0.715
		btnStart.y = _H * 0.63 + 3
		groupMain:insert(btnStart)
                
                local btnExit = widget.newButton{
			label="Thoát",
			labelColor = {default={248,217,6}, over={128} },
                        fontSize = 36,
			default="images/btn_on.png",
			over="images/btn_over.png",
			--width=54, height=40,
			onRelease = function(event)
				---showMenuPopup()
--                              storyboard.gotoScene( "gcontact")  
			end
		}
                btnExit.xScale, btnExit.yScale = 0.315, 0.48
		btnExit.x = btnStart.x
		btnExit.y = btnStart.y + btnStart.height/2 + 10
		groupMain:insert(btnExit)
	end
	-----------------------------------------------------------------------------------------
	-- Called immediately after scene has moved onscreen:
	-----------------------------------------------------------------------------------------
	function scene:enterScene( event )
		local group = self.view
		-- INSERT code here (e.g. start timers, load audio, start listeners, etc.)
		--initGame(group)
	end
	-----------------------------------------------------------------------------------------
	-- Called when scene is about to move offscreen:
	-----------------------------------------------------------------------------------------
	function scene:exitScene( event )
		local group = self.view
	end
	-----------------------------------------------------------------------------------------
	-- If scene's view is removed, scene:destroyScene() will be called just prior to:
	-----------------------------------------------------------------------------------------
	function scene:destroyScene( event )
		local group = self.view
	end
	-----------------------------------------------------------------------------------------
	-- END OF YOUR IMPLEMENTATION
	-----------------------------------------------------------------------------------------
	-- "createScene" event is dispatched if scene's view does not exist
	scene:addEventListener( "createScene", scene )
	-- "enterScene" event is dispatched whenever scene transition has finished
	scene:addEventListener( "enterScene", scene )

	-- "exitScene" event is dispatched whenever before next scene's transition begins
	scene:addEventListener( "exitScene", scene )
	-- "destroyScene" event is dispatched before view is unloaded, which can be
	-- automatically unloaded in low memory situations, or explicitly via a call to
	-- storyboard.purgeScene() or storyboard.removeScene().
	scene:addEventListener( "destroyScene", scene )
	-----------------------------------------------------------------------------------------
	return scene